package top.chatgqt.SmartChargeStation.config;

import lombok.extern.slf4j.Slf4j;
import org.apache.iotdb.session.Session;
import org.apache.iotdb.session.pool.SessionPool;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@Slf4j
public class IotDBSessionConf {
    @Value("${iotdb.username}")
    private String username;

    @Value("${iotdb.password}")
    private String password;

    @Value("${iotdb.ip}")
    private String ip;

    @Value("${iotdb.port}")
    private int port;

    @Value("${iotdb.maxSize}")
    private int maxSize;

    private SessionPool pool;

    @Bean
    public SessionPool initSessionPool() {

        log.info(">>>>> SessionPool init");
        if (pool == null) {
            pool = new SessionPool.Builder()
                    .user(username)
                    .password(password)
                    .host(ip)
                    .port(port)
                    .maxSize(maxSize)
                    .build();
        }

        return pool;
    }
}
